//
//  ZSNavicationController.swift
//  ZSWeibo
//
//  Created by zsj1992 on 16/4/6.
//  Copyright © 2016年 ichange. All rights reserved.
//

import UIKit

class ZSNavicationController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

self.interactivePopGestureRecognizer?.delegate = self
    }
    
    
    //重写nav的push方法
    override func pushViewController(viewController: UIViewController, animated: Bool) {


        if viewControllers.count>0{
        
        let backTitle = viewControllers.count==1 ? (viewControllers.first?.title ?? ""):"返回"
        
        viewController.navigationItem.leftBarButtonItem = UIBarButtonItem.creatItem("navigationbar_back_withtext",target: self, action: "backBtnDidClick",title:backTitle)
}
        
        super.pushViewController(viewController, animated: true)

    }


    
    
    func backBtnDidClick(){
        
        popViewControllerAnimated(true)
    }
    
    // 实现代理方法,解决手势拖拽的bug,首页拖了,会乱掉
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        return viewControllers.count != 1
    }
    

    
}